package org.misty.redis.autoconfigure.filter;

import lombok.extern.slf4j.Slf4j;
import org.misty.redis.bloomfilter.BloomFilter;
import org.misty.redis.client.RedisClient;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.annotation.PostConstruct;

/**
 * @author Misty on 2020-06-10
 */
@Slf4j
@AutoConfigureAfter(MultiFilterRegistrar.class)
@Configuration(proxyBeanMethods = false)
@ConditionalOnExpression("${redis-tools.filter.default.enabled:true}")
@ConditionalOnMissingBean(BloomFilter.class)
@EnableConfigurationProperties({DefaultFilterProperties.class})
public class DefaultFilterAutoConfiguration {
    @PostConstruct
    private void init() {
        log.info("***** DefaultFilterAutoConfiguration");
    }

    @Bean
    public BloomFilter bloomFilter(RedisClient redisClient, DefaultFilterProperties config) {
        log.info("BloomFilter defaults active! Set 'redis-tools.filter.default.enabled' to 'false' to disable");
        return new BloomFilter(redisClient, config);
    }
}
